import update from './atom/db/update';
import query from './atom/db/query';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	student_no: string,
	student_name: string,
	student_id: string,
	student_type: string,
	sex: string,
}

async function atom(msg: Message) {
	const systemid = '5981';
	const q = query(action_id, session_id, spaceid, systemid);
	q.prepare('arrange_exam_student', ['_id'], { student_no: msg.student_no }, 1, 1);
	const [student] = await q.exec();
	console.log(student);
	const _id = student[0]._id;
	const _upd = Object.assign({ _id }, msg);
	const upd = update(action_id, session_id, spaceid, systemid);
	upd.prepare('arrange_exam_student', [_upd]);
	const ret = await upd.exec();
	if (ret.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
